package demo06;

public class Test06 {
    public static void main1(String[] args) {
        Student stu1 = new Student("张三",18,99);
        Student stu2 = new Student("李四",20 , 97);

        //通过大于号小于号进行比较的时候 ， 是不能比较引用类型的
        //编译器要求给一个比较大小的规则

        //比较两个人年龄大小
        if (stu1.compareTo(stu2)>0){
            System.out.println("stu1 > stu2");
        }else if (stu1.compareTo(stu2)==0){
            System.out.println("stu1 = stu2");
        }else {
            System.out.println("stu1 < stu2");
        }
    }
    //更优的方法
    //相比较下 comparator 的侵略性比较低
    public static void main(String[] args) {
        Student stu1 = new Student("张三",18,99);
        Student stu2 = new Student("李四",20 , 97);
        //判断年龄大小
        AgeComparator ageComparator = new AgeComparator();
        if (ageComparator.compare(stu1,stu2) > 0){
            System.out.println("stu1 > stu2");
        } else if (ageComparator.compare(stu1,stu2) == 0) {
            System.out.println("stu1 = stu2");
        }else {
            System.out.println("stu1 < stu2");
        }
        System.out.println("-----");
        //判断成绩
        ScoreComparator scoreComparator = new ScoreComparator();
        if (scoreComparator.compare(stu1,stu2)>0){
            System.out.println("stu1 > stu2");
        } else if (scoreComparator.compare(stu1,stu2)==0) {
            System.out.println("stu1 = stu2");
        }else {
            System.out.println("stu1 < stu2");
        }
    }
}
